<%@ page pageEncoding="UTF-8" contentType="text/html; charset=UTF-8"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>
<!DOCTYPE html>

<html>
    <head>
	
		<%@ include file="/WEB-INF/views/include/common.jsp" %>
		<meta name="AUTHOR" content="QroTech Inc." />
		<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
		<meta http-equiv="CACHE-CONTROL" content="NO-CACHE">
		<meta http-equiv="PRAGMA" content="NO-CACHE">
		<meta name="ROBOTS" content="NOINDEX, NOFOLLOW">
		<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1" />
		<title>큐로넷::위치관제시스템</title>
		
		<link rel="stylesheet" href="${cssUrl}/m-421.css" type="text/css" />
		<link rel="stylesheet" href="${cssUrl}/button.css" type="text/css" />
		<script src="${jsUrl}/pagenation.js"></script>
		<script src="${jsUrl}/windowSize.js"></script>
		
    </head>
    <body onload="init()">
    	<div class="m421">
    		<form id="theForm" name="theForm"  method="post" enctype="multipart/form-data">
    		<input type="hidden" name="boardType" id="boardType" value="${param.boardType}"/>
    		<input type="hidden" name="mode" id="mode" value="${param.mode}"/>
    		<input type="hidden" name="textID" id="textID" value="${param.textID}"/>
    		<input type="hidden" name="textNum" value="${param.textNum}"/>
    		<input type="hidden" name="isHelp" id="isHelp" value="${param.isHelp}"/>
    		<table class="write">
    			<tr><td class="title">글쓰기</td></tr>
    			<tr>
    				<td>
    					<table cellpadding="0" cellspacing="0">
    						<tr>
    							<th >작성자</th>
    							<td><c:out value="${loginID}"/></td>
    						</tr>
    						<tr>
    							<th>제목</th>
    							<td><input type="text" name="title" id="title"/></td>
    						</tr>
    						<tr class="content">
    							<th>내용</th>
    							<td><%@ include file="/resources/daumEditor/editor.jsp" %></td>
    						</tr>
    						<c:if test="${param.boardType != 1}">
    						<tr>
    							<th>첨부 파일</th>
    							<td><input type="file" name="attachementFile" id="file" style="width:100%;"></td>
    						</tr>
    						</c:if>
    					</table>
    				</td>
    			</tr>
    			<tr>
    				<td colspan="2"><div class="button"><a onClick="onRegist();" class="button1">등록</a> <a onClick="javascript:self.close()" class="button1">취소</a></div></td>
    			</tr>
    		</table>
    		<textarea name="contents" id="contents" style="display:none;"></textarea>
    		</form>
    		
    	</div>
    	
		<script language="javascript">
			function init() {
				var boardType = <c:out value="${boardType}" />;
				var type = <c:out value="${type}" />;
				var isHelp = $("#isHelp").val();
				
				if(type > 0) {
					if(type == 1) {
						alert('글이 저장되었습니다.');
					} else if(type == 2) {
						alert('수정되었습니다.');
					}
					if (isHelp == 'y') {
						window.opener.location.href="/helper/helperQnaListMain";
					} else {
						if(boardType == 1) {
							window.opener.location.href = "/admin/adminNoticeListMain";
						} else if(boardType == 2){
							window.opener.location.href = "/admin/adminQnaListMain";
						} else {
							window.opener.location.href = "/admin/adminArchivesListMain";
						}	
					}						
					self.close();
				} else {
					getBoardData();
				}
			}
			function getBoardData() {
				var mode = $("#mode").val();
				var param = "";
				if(mode == 'update') {
					param = $("#theForm").serialize();
					
					var url='getBoardData.json';
					AjaxPost(url, param, function(data){
						$("#title").val(data.boardView["title"]);
						modifyContent(data.boardView["contents"]);
					});
				}				
			}
			function onRegist() {
				var title = $("#title").val();
				if(title == '') {
					alert('제목을 입력하세요.');
					$('#title').focus();
					return;
				}
				var content = Editor.getContent();
				if(content == '') {
					alert("내용을 입력하세요.");
					return;
				}
				$("#contents").val(content);
				var boardType = $("#boardType").val();
				if(boardType != 1) {
					var fileName = $("#file").val();
					if (fileName != '') {
						var fileSize = $("#file")[0].files[0].size;
						if (fileSize > 10 * 1024 * 1024) {
							alert("10M 미만으로 입력하세요.");
							return;
						}
// 						var name = fileName.split('\\').pop();
// 						var id_pattern = new RegExp('[ㄱ-힣]'); 
// 						if (id_pattern.test(name)) {
// 							alert("영문 파일명으로 입력하세요.");
// 							return;
// 						}
					}
				}
				$("#theForm").attr("action", "/admin/registBoard");
				document.theForm.submit();
			}
			
		</script>
	
  	</body>
</html>
